function Quicksort(arr) {
    if (arr.length <= 1) {
        return arr
    }
    let baseNumIndex = Math.floor(arr.length / 2)
    let baseNum = arr.splice(baseNumIndex, 1)[0]
    console.log(baseNum)
    let left_arr = []
    let right_arr = []
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] < baseNum) {
            left_arr.push(arr[i])
        } else {
            right_arr.push(arr[i])
        }
    }
    let new_arr = []
    new_arr.push(left_arr.concat(right_arr))
    return Quicksort(left_arr).concat([baseNum], Quicksort(right_arr))
}

arr = [5, 1, 34, 76, 23, 98, 21, 54, 79]
console.log(Quicksort(arr))
